package com.fenghuajueli.libbasecoreui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;

import com.fenghuajueli.libbasecoreui.R;
import com.fenghuajueli.libbasecoreui.listener.OnListClickListener;

/**
 * 草稿箱列表更多操作对话框
 */
public class DraftsMoreActionDialog extends Dialog {

    LinearLayout llRenameContainer;
    LinearLayout llDeleteContainer;
    LinearLayout llCopyContainer;
    private OnListClickListener<Integer> onListClickListener;


    public DraftsMoreActionDialog(Context context) {
        super(context, R.style.StyleBaseDialog);
    }

    public void setOnListClickListener(OnListClickListener<Integer> onListClickListener) {
        this.onListClickListener = onListClickListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_drafts_more_action_layout);
        llRenameContainer = findViewById(R.id.llRenameContainer);
        llDeleteContainer = findViewById(R.id.llDeleteContainer);
        llCopyContainer = findViewById(R.id.llCopyContainer);
        llRenameContainer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onListClickListener != null) {
                    onListClickListener.itemClick(0, 0);
                }
                dismiss();
            }
        });
        llCopyContainer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onListClickListener != null) {
                    onListClickListener.itemClick(1, 1);
                }
                dismiss();
            }
        });
        llDeleteContainer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onListClickListener != null) {
                    onListClickListener.itemClick(2, 2);
                }
                dismiss();
            }
        });
    }

    @Override
    public void show() {
        super.show();
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.gravity = Gravity.BOTTOM;
        getWindow().setAttributes(layoutParams);
    }
}
